<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="css sprite," />





  <link rel="alternate" href="/atom.xml" title="OBKoro1's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="写在前面：在网页制作中，雪碧图也是前端攻城狮必须掌握的一项小技能。百度词条对雪碧图的解释是：CSS雪碧 即CSS Sprite，也有人叫它CSS精灵，是一种CSS图像合并技术，该方法是将小图标和背景图像合并到一张图片上，然后利用css的背景定位来显示需要显示的图片部分。本文主要内容包括雪碧图如何制作，雪碧图优缺点，哪些场景需要使用雪碧图。 实现原理：CSS雪碧的基本原理是把你的网站上用到的一些图片">
<meta name="keywords" content="css sprite">
<meta property="og:type" content="article">
<meta property="og:title" content="css sprite雪碧图制作，使用以及相关，图文gif">
<meta property="og:url" content="http://yoursite.com/2017/10/11/css-sprite雪碧图制作，使用以及相关，图文gif/index.html">
<meta property="og:site_name" content="OBKoro1&#39;s Blog">
<meta property="og:description" content="写在前面：在网页制作中，雪碧图也是前端攻城狮必须掌握的一项小技能。百度词条对雪碧图的解释是：CSS雪碧 即CSS Sprite，也有人叫它CSS精灵，是一种CSS图像合并技术，该方法是将小图标和背景图像合并到一张图片上，然后利用css的背景定位来显示需要显示的图片部分。本文主要内容包括雪碧图如何制作，雪碧图优缺点，哪些场景需要使用雪碧图。 实现原理：CSS雪碧的基本原理是把你的网站上用到的一些图片">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/07f57ff83cec9de20cb2">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/0cc59dfda362991ef28f">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/540b6855a8f1cd63afa4">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/fe5a1265957120cf390a.gif">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/9eda37300841b0915105">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/d4ecfa490c99fdc03522">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/6b862bdd46e619ea2802">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/1b5c1e3609129f5b58a9.gif">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/fca91f283b5ac39592a3">
<meta property="og:updated_time" content="2019-06-15T06:19:47.625Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="css sprite雪碧图制作，使用以及相关，图文gif">
<meta name="twitter:description" content="写在前面：在网页制作中，雪碧图也是前端攻城狮必须掌握的一项小技能。百度词条对雪碧图的解释是：CSS雪碧 即CSS Sprite，也有人叫它CSS精灵，是一种CSS图像合并技术，该方法是将小图标和背景图像合并到一张图片上，然后利用css的背景定位来显示需要显示的图片部分。本文主要内容包括雪碧图如何制作，雪碧图优缺点，哪些场景需要使用雪碧图。 实现原理：CSS雪碧的基本原理是把你的网站上用到的一些图片">
<meta name="twitter:image" content="https://dn-mhke0kuv.qbox.me/07f57ff83cec9de20cb2">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/10/11/css-sprite雪碧图制作，使用以及相关，图文gif/"/>





  <title>css sprite雪碧图制作，使用以及相关，图文gif | OBKoro1's Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64d57d0b926bbd27431daa89d2e0a76b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">OBKoro1's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-前端算法">
          <a href="/arithmetic/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            前端算法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-博客最新更新">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            博客最新更新
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/11/css-sprite雪碧图制作，使用以及相关，图文gif/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OBKoro1">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/hand1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="OBKoro1's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">css sprite雪碧图制作，使用以及相关，图文gif</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-11T22:21:46+08:00">
                2017-10-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/工具类/" itemprop="url" rel="index">
                    <span itemprop="name">工具类</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2017/10/11/css-sprite雪碧图制作，使用以及相关，图文gif/" class="leancloud_visitors" data-flag-title="css sprite雪碧图制作，使用以及相关，图文gif">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1,311 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="写在前面："><a href="#写在前面：" class="headerlink" title="写在前面："></a>写在前面：</h2><p>在网页制作中，<strong>雪碧图也是前端攻城狮必须掌握的一项小技能</strong>。百度词条对雪碧图的解释是：CSS雪碧 即CSS Sprite，也有人叫它CSS精灵，是一种CSS图像合并技术，该方法是将小图标和背景图像合并到一张图片上，然后利用css的背景定位来显示需要显示的图片部分。本文主要内容包括雪碧图如何制作，雪碧图优缺点，哪些场景需要使用雪碧图。</p>
<h3 id="实现原理："><a href="#实现原理：" class="headerlink" title="实现原理："></a>实现原理：</h3><p>CSS雪碧的基本原理是把你的网站上用到的一些图片整合到一张单独的图片中，从而减少你的网站的HTTP请求数量。该图片使用CSS background和background-position属性渲染，这也就意味着你的标签变得更加复杂了，图片是在CSS中定义，而非img标签。</p>
<h2 id="1-前期准备下载工具：css-sprit（css精灵）"><a href="#1-前期准备下载工具：css-sprit（css精灵）" class="headerlink" title="1.前期准备下载工具：css sprit（css精灵）"></a>1.前期准备下载工具：css sprit（css精灵）</h2><p>长这样：<br><img src="https://dn-mhke0kuv.qbox.me/07f57ff83cec9de20cb2" alt="css sprit"></p>
<p>看图片就知道多好用！</p>
<p>文件不到200k，相当轻便，这是百度云链接：<a href="http://pan.baidu.com/s/1nuOZDqT" target="_blank" rel="noopener">http://pan.baidu.com/s/1nuOZDqT</a></p>
<p>也有mac版本的，这是链接：<a href="http://dl.pconline.com.cn/download/421423.html" target="_blank" rel="noopener">http://dl.pconline.com.cn/download/421423.html</a></p>
<h2 id="2-使用方法"><a href="#2-使用方法" class="headerlink" title="2.使用方法"></a>2.使用方法</h2><p>下载，打开之后。<br>1.首先要切一些图片，不会切的话，移步：<a href="https://juejin.im/post/58e9deacb123db1ad05fab2f" target="_blank" rel="noopener">《前端ps切图方法，图文详细》</a></p>
<h2 id="2-打开雪碧图，选择图片。"><a href="#2-打开雪碧图，选择图片。" class="headerlink" title="2.打开雪碧图，选择图片。"></a>2.打开雪碧图，选择图片。</h2><p><img src="https://dn-mhke0kuv.qbox.me/0cc59dfda362991ef28f" alt=""></p>
<h2 id="3-添加完图片之后，会自动生成代码，需要排列一下图片："><a href="#3-添加完图片之后，会自动生成代码，需要排列一下图片：" class="headerlink" title="3.添加完图片之后，会自动生成代码，需要排列一下图片："></a>3.添加完图片之后，会自动生成代码，需要排列一下图片：</h2><p><img src="https://dn-mhke0kuv.qbox.me/540b6855a8f1cd63afa4" alt=""></p>
<p><img src="https://dn-mhke0kuv.qbox.me/fe5a1265957120cf390a.gif" alt="可以看到我排列图片的时候，下面的代码也会跟着刷新"></p>
<p>可以看到排列图片的时候，下面的代码也会跟着刷新</p>
<p>注意：排列图片的时候要注意各个图片之间留点空隙，不然使用的时候，会相互覆盖。</p>
<h2 id="3-保存图片以及雪碧图css代码"><a href="#3-保存图片以及雪碧图css代码" class="headerlink" title="3.保存图片以及雪碧图css代码"></a>3.保存图片以及雪碧图css代码</h2><p>保存雪碧图<br><img src="https://dn-mhke0kuv.qbox.me/9eda37300841b0915105" alt=""></p>
<p>生成的雪碧图：<br><img src="https://dn-mhke0kuv.qbox.me/d4ecfa490c99fdc03522" alt=""><br>保存雪碧图-css代码（因为软件没有到导出css代码的功能，所以要自己新建一个txt文件，放在雪碧图旁边，以后打开txt就知道图片在雪碧图的位置。）</p>
<p><img src="https://dn-mhke0kuv.qbox.me/6b862bdd46e619ea2802" alt=""></p>
<p>gif操作：</p>
<p><img src="https://dn-mhke0kuv.qbox.me/1b5c1e3609129f5b58a9.gif" alt=""></p>
<h2 id="如何在html中使用？"><a href="#如何在html中使用？" class="headerlink" title="如何在html中使用？"></a>如何在html中使用？</h2><p>慕课网雪碧图：</p>
<p><img src="https://dn-mhke0kuv.qbox.me/fca91f283b5ac39592a3" alt=""><br>慕课网demo：<a href="http://www.imooc.com/code/1511。" target="_blank" rel="noopener">http://www.imooc.com/code/1511。</a><br>慕课网雪碧图教程：<a href="http://www.imooc.com/learn/93" target="_blank" rel="noopener">http://www.imooc.com/learn/93</a></p>
<h2 id="3-雪碧图优劣势"><a href="#3-雪碧图优劣势" class="headerlink" title="3.雪碧图优劣势"></a>3.雪碧图优劣势</h2><h3 id="1-加快网页加载速度"><a href="#1-加快网页加载速度" class="headerlink" title="1.加快网页加载速度"></a>1.加快网页加载速度</h3><p>网页上面每一张图片，都要向浏览器请求下载图片，而浏览器接受的同时请求数是10个，一次能处理的请求数目是两个。</p>
<p>http发起请求，最耗时的是在三次握手，每次请求之前都要握手。所以在网页性能优化中，减少http请求的次数是相当重要的一点！（本来想写多一点，但有些知识点不太清楚，怕误人子弟就不再赘述了。）</p>
<p>当一个网页有几百张，几千张图片的时候加载起来简直了！而且对于不稳定的网络带宽，加载起来更是噩梦，所以把图片拼接为一张大图，从而加快加载速度，以及加速页面渲染</p>
<h3 id="2-后期维护简单"><a href="#2-后期维护简单" class="headerlink" title="2.后期维护简单"></a>2.后期维护简单</h3><p>该工具可以直接通过选择图片进行图片的拼接，当然你也可以自己挪动里面的图片，自己去布局你的雪碧图，更换图片的时候也只要更改一下图片的位置就可以了。直接生成代码，简单易用</p>
<p><strong>3、CSS Sprites能减少图片的字节</strong>，曾经比较过多次3张图片合并成1张图片的字节总是小于这3张图片的字节总和。</p>
<p><strong> 4、解决了网页设计师在图片命名上的困扰</strong>，只需对一张集合的图片上命名就可以了，不需要对每一个小元素进行命名，从而提高了网页的制作效率。</p>
<p> <strong>5、更换风格方便</strong>，只需要在一张或少张图片上修改图片的颜色或样式，整个网页的风格就可以改变。维护起来更加方便。</p>
<h3 id="关于雪碧图的缺点内容：不要滥用雪碧图sprite"><a href="#关于雪碧图的缺点内容：不要滥用雪碧图sprite" class="headerlink" title="关于雪碧图的缺点内容：不要滥用雪碧图sprite"></a>关于雪碧图的缺点内容：<a href="http://www.cnblogs.com/joyho/articles/3715275.html" target="_blank" rel="noopener">不要滥用雪碧图sprite</a></h3><p>里面说了蛮多的，这事情可以根据使用场景来决定，大家可以看看，毕竟我是来教雪碧图的。。。<br>下面有关于雪碧图的demo。</p>
<p>之前写过两篇相关的：<br>1.<a href="https://juejin.im/post/58e9deacb123db1ad05fab2f" target="_blank" rel="noopener">前端ps切图方法，图文详细</a><br>2.<a href="https://juejin.im/post/58ec558d570c350057e849f0" target="_blank" rel="noopener">ps切图实用小技巧、图片格式的区别及相关内容</a></p>
<p>以上，2017.4.10。</p>
<p><strong>最后又到了观众朋友们最喜欢的求赞求关注环节：</strong>希望看完的朋友点个喜欢，也可以关注一下我，现在这阶段基本上每个月都不会少于十五篇文章（看到干货我也会进行分享）。码字不易，感谢支持，感激不尽！<br><strong>ps</strong>：目前待业，坐标北京，求推荐工作。然后希望我写哪方面的文章可以在底下评论，或者是私信我，虽然写的不好，但我就当这是记录自己成长的一种方式咯。（前提是我会了，如果不会我也会记下来，等会了的时候再更出来。）<br><a href="http://www.jianshu.com/u/8d1dd8c80f06" target="_blank" rel="noopener"><em>**</em></a><strong><a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" rel="noopener">掘金个人主页</a>  ，</strong><a href="http://www.jianshu.com/u/8d1dd8c80f06" target="_blank" rel="noopener"><strong>简书主页链接</strong></a>，<strong><a href="http://blog.csdn.net/OBKoro1?skin=dark1" target="_blank" rel="noopener">csdn博客主页链接</a> ，<a href="https://github.com/OBKoro1" target="_blank" rel="noopener">github</a> 。</strong></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>听说，打赏我的人最后都找到了真爱。</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/pay/weixin.jpg" alt="OBKoro1 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/pay/ali.jpg" alt="OBKoro1 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/css-sprite/" rel="tag"><i class="fa fa-tag"></i> css sprite</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/10/11/前端-PS-切图方法，图文详细/" rel="next" title="前端 PS 切图方法，图文详细">
                <i class="fa fa-chevron-left"></i> 前端 PS 切图方法，图文详细
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/11/ps切图实用小技巧、图片格式的区别及相关内容/" rel="prev" title="ps切图实用小技巧、图片格式的区别及相关内容">
                ps切图实用小技巧、图片格式的区别及相关内容 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/uploads/hand1.jpg"
              alt="OBKoro1" />
          
            <p class="site-author-name" itemprop="name">OBKoro1</p>
            <p class="site-description motion-element" itemprop="description">种一棵树最好的时间是十年前,其次是现在</p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives">
            
                <span class="site-state-item-count">105</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">74</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/OBKoro1" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" title="掘金">
                  
                    <i class="fa fa-fw fa-globe"></i>掘金</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://obkoro1.com/web_accumulate/" target="_blank" title="前端积累">
                  
                    <i class="fa fa-fw fa-globe"></i>前端积累</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://segmentfault.com/u/obkoro1/articles" target="_blank" title="segmentfault">
                  
                    <i class="fa fa-fw fa-globe"></i>segmentfault</a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#写在前面："><span class="nav-number">1.</span> <span class="nav-text">写在前面：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实现原理："><span class="nav-number">1.1.</span> <span class="nav-text">实现原理：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-前期准备下载工具：css-sprit（css精灵）"><span class="nav-number">2.</span> <span class="nav-text">1.前期准备下载工具：css sprit（css精灵）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-使用方法"><span class="nav-number">3.</span> <span class="nav-text">2.使用方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-打开雪碧图，选择图片。"><span class="nav-number">4.</span> <span class="nav-text">2.打开雪碧图，选择图片。</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-添加完图片之后，会自动生成代码，需要排列一下图片："><span class="nav-number">5.</span> <span class="nav-text">3.添加完图片之后，会自动生成代码，需要排列一下图片：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-保存图片以及雪碧图css代码"><span class="nav-number">6.</span> <span class="nav-text">3.保存图片以及雪碧图css代码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#如何在html中使用？"><span class="nav-number">7.</span> <span class="nav-text">如何在html中使用？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-雪碧图优劣势"><span class="nav-number">8.</span> <span class="nav-text">3.雪碧图优劣势</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-加快网页加载速度"><span class="nav-number">8.1.</span> <span class="nav-text">1.加快网页加载速度</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-后期维护简单"><span class="nav-number">8.2.</span> <span class="nav-text">2.后期维护简单</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关于雪碧图的缺点内容：不要滥用雪碧图sprite"><span class="nav-number">8.3.</span> <span class="nav-text">关于雪碧图的缺点内容：不要滥用雪碧图sprite</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 &mdash; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OBKoro1</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">
      156.0k
    </span>
  
</div>




<div>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span class="site-uv"><i class="fa fa-user"></i> 访问用户： <span class="busuanzi-value" id="busuanzi_value_site_uv">21621</span> 人 </span>
<span class="site-pv"><i class="fa fa-eye"></i> 访问次数： <span class="busuanzi-value" id="busuanzi_value_site_pv">68503</span> 次</span>

</div>



        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("9ANFp60h6oVyxIPGlau3NOA4-gzGzoHsz", "tMdNuKMbFtN4QsekeNVu83TV");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>

